<style type="text/css">
    .layui-table-body{overflow-x:auto;}
    .layui-table-cell{font-size:12px;}
</style>
<div class="layui-form hisi-search">
    <form action="{:url()}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-block">
                <input type="text" name="keyword" class="layui-input" lay-verify="required" placeholder="邮箱/手机/昵称" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员卡号</label>
            <div class="layui-input-block">
                <input type="text" name="sb_card" class="layui-input" lay-verify="required" placeholder="会员卡号" />
            </div>
        </div>
        <div class="layui-form-item hisi-search-btn">
            <div class="layui-input-block" style="width: 300px;">
                <button type="submit" class="layui-btn layui-btn-normal layui-icon layui-icon-search">查询</button>
                <!-- <button type="reset" class="layui-btn layui-btn-primary layui-icon layui-icon-delete">重置</button> -->
                <button type="button" class="layui-btn layui-btn-warm layui-icon layui-icon-download-circle export">导出</button>
                <button type="button" class="layui-btn layui-btn-primary layui-icon layui-icon-download-circle import">导入会员</button>

            </div>
        </div>
    </form>
</div>
<table id="dataTable"></table>
<script type="text/html" id="usernameTpl">
    <div style="line-height:18px;">
    <p class="ml10 fl"><strong class="mcolor">{{ d.username }} ({{ d.nick }})</strong><br>手机：{{ d.mobile }}<br>邮箱：{{ d.email }}</p></div>
</script>
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.status == 1 ? 'checked' : '' }} data-href="{:url('status')}?id={{ d.id }}">
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '550px', height: '420px', title: '修改会员'}">修改</a>
    <a href="{:url('getBalanceList')}?user_id={{ d.id }}" title="查看详情" class="layui-btn layui-btn-xs layui-btn-normal">查看详情</a>
    <!-- <a href="{:url('getBalanceList')}?user_id={{ d.id }}" title="查看详情" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop" hisi-data="{width: `800px`, height: `600px`, title: `查看详情`}">查看详情</a> -->
    <a href="{:url('del')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>

</script>
{include file="system@block/layui" /}
<script id="toolbar" type="text/html">
    <a href="{:url('add')}" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe-pop" hisi-data="{width: '550px', height: '420px', title: '添加会员'}">&nbsp;添加</a>

    <a data-href="{:url('del')}" class="layui-btn layui-btn-danger j-page-btns confirm layui-btn-sm">&nbsp;删除</a>
</script>
<script type="text/javascript">
    layui.use(['table','jquery','upload'], function() {
        var table = layui.table;
        var $ = layui.jquery;
        var upload = layui.upload;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'id', title: '会员编号'}
                ,{field: 'nick', title: '会员'}
                ,{field: 'sb_card', title: '会员卡号'}
                ,{field: 'vx', title: '微信'}
                ,{field: 'email', title: '邮箱'}
                ,{field: 'mobile', title: '手机号'}
                ,{field: 'sex', title: '性别',templet:function(d){
                    if(d.sex == 1){
                        return '<span style="color:green">男</span>';
                    }else{
                        return '<span style="color:red">女</span>';
                    }
                }}
                ,{field: 'birthday', title: '生日'}
                ,{field: 'info', title: '基本信息',templet:function(d){
                    return '身高：'+d.height + 'CM<br>'+'体重：'+ d.weight +'KG'
                }}
                ,{field: 'user_project', title: '疗程卡'}
                ,{field: 'user_product', title: '产品卡'}
                ,{field: 'user_balance', title: '会员卡'}
                ,{field: 'user_balance_zeng', title: '会员卡赠送'}
                ,{field: 'last_login_time', title: '上次到店时间'}
                ,{field: 'ctime', title: '加入时间',sort:true}
                ,{field: 'shop', title: '门店名称',templet:function(d){
                    return d.has_shop.name
                }}
                ,{field: 'status', title: '状态',  templet: '#statusTpl'}
                ,{title: '操作', width: 200, templet: '#buttonTpl'}
            ]]
            ,done: function(){
                if (typeof(layui.global.addTableTool) !== 'undefined') {
                    layui.global.addTableTool();
                }
            }
        });

        //指定允许上传的文件类型
         upload.render({
           elem: '.import'
           ,url: '{:url('import')}' //改成您自己的上传接口
           ,accept: 'file' //普通文件
           ,done: function(res){
             layer.msg('上传成功');
             console.log(res);
           }
         });

        $(document).on('click', '.export', function(){
              var form = $('#hisi-table-search').serializeArray();
              var where = new Array();
              form.push({name:'operation',value:2});
              $.ajax({
                  url:"{:url()}",
                  type:'get',
                  data:form,
                  success:function(res){
                      if(res.code == 200){
                          window.location.href=res.msg;
                      }else{
                          layer.msg(res.msg);
                      }

                  }
              })
              return ;
        })
    });
</script>
